package org.cadad.test;

import java.util.Calendar;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.RadioButton;
import android.widget.TextView;

public class Tab_Uno extends Activity {

	static final String[] COUNTRIES = new String[] { "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda",
			"Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda",
			"Bhutan", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Bouvet Island", "Brazil", "British Indian Ocean Territory", "British Virgin Islands", "Brunei", "Bulgaria",
			"Burkina Faso", "Burundi", "Cote d'Ivoire", "Cambodia", "Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
			"Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo", "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czech Republic",
			"Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea",
			"Eritrea", "Estonia", "Ethiopia", "Faeroe Islands", "Falkland Islands", "Fiji", "Finland", "Former Yugoslav Republic of Macedonia", "France", "French Guiana",
			"French Polynesia", "French Southern Territories", "Gabon", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam",
			"Guatemala", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Heard Island and McDonald Islands", "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia",
			"Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Kuwait", "Kyrgyzstan", "Laos", "Latvia", "Lebanon",
			"Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", "Macau", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta",
			"Marshall Islands", "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia", "Moldova", "Monaco", "Mongolia", "Montserrat", "Morocco", "Mozambique",
			"Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Niue",
			"Norfolk Island", "North Korea", "Northern Marianas", "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines",
			"Pitcairn Islands", "Poland", "Portugal", "Puerto Rico", "Qatar", "Reunion", "Romania", "Russia", "Rwanda", "Sqo Tome and Principe", "Saint Helena",
			"Saint Kitts and Nevis", "Saint Lucia", "Saint Pierre and Miquelon", "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Saudi Arabia", "Senegal",
			"Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Georgia and the South Sandwich Islands",
			"South Korea", "Spain", "Sri Lanka", "Sudan", "Suriname", "Svalbard and Jan Mayen", "Swaziland", "Sweden", "Switzerland", "Syria", "Taiwan", "Tajikistan", "Tanzania",
			"Thailand", "The Bahamas", "The Gambia", "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Turks and Caicos Islands", "Tuvalu",
			"Virgin Islands", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan",
			"Vanuatu", "Vatican City", "Venezuela", "Vietnam", "Wallis and Futuna", "Western Sahara", "Yemen", "Yugoslavia", "Zambia", "Zimbabwe" };

	private TextView mDateDisplayFrom;
	private Button mPickDateFrom;

	private TextView mDateDisplayTo;
	private Button mPickDateTo;

	private int mYear;
	private int mMonth;
	private int mDay;

	static final int DATE_DIALOG_ID_FROM = 0;
	static final int DATE_DIALOG_ID_TO = 1;

	private RadioButton rb1;
	private RadioButton rb2;

	// private Button b1;
	// private TextView t1;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.tab_uno);
		TabTestActivity.gActivity = this;

		rb1 = (RadioButton) findViewById(R.id.option1);
		rb2 = (RadioButton) findViewById(R.id.option2);
//		b1 = (Button) findViewById(R.id.selected);
//		b1.setOnClickListener(this);
//		t1 = (TextView) findViewById(R.id.TextView01);

		AutoCompleteTextView textViewFrom = (AutoCompleteTextView) findViewById(R.id.autocomplete_country_from);
		ArrayAdapter<String> adapterFrom = new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES);
		textViewFrom.setAdapter(adapterFrom);

		AutoCompleteTextView textViewTo = (AutoCompleteTextView) findViewById(R.id.autocomplete_country_to);
		ArrayAdapter<String> adapterTo = new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES);
		textViewTo.setAdapter(adapterTo);

		// capture our View elements
		mDateDisplayFrom = (TextView) findViewById(R.id.dateDisplayFrom);
		mPickDateFrom = (Button) findViewById(R.id.pickDateFrom);

		// add a click listener to the button
		mPickDateFrom.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				showDialog(DATE_DIALOG_ID_FROM);
			}
		});

		// capture our View elements
		mDateDisplayTo = (TextView) findViewById(R.id.dateDisplayTo);
		mPickDateTo = (Button) findViewById(R.id.pickDateTo);

		// add a click listener to the button
		mPickDateTo.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				showDialog(DATE_DIALOG_ID_TO);
			}
		});

		// get the current date
		final Calendar c = Calendar.getInstance();
		mYear = c.get(Calendar.YEAR);
		mMonth = c.get(Calendar.MONTH);
		mDay = c.get(Calendar.DAY_OF_MONTH);

		// display the current date
		updateDisplay(mDateDisplayFrom);
		updateDisplay(mDateDisplayTo);

	};

	@Override
	// public void onClick(View v) {
	// if (v == b1) {
	// if (rb1.isChecked() == true)
	// t1.setText("Selected is : " + rb1.getText());
	// if (rb2.isChecked() == true)
	// t1.setText("Selected is : " + rb2.getText());
	// }
	// }

	protected Dialog onCreateDialog(int id) {
		switch (id) {
		case DATE_DIALOG_ID_FROM:
			return new DatePickerDialog(this, mDateSetListenerFrom, mYear, mMonth, mDay);
		case DATE_DIALOG_ID_TO:
			return new DatePickerDialog(this, mDateSetListenerTo, mYear, mMonth, mDay);
		}
		return null;
	}

	// updates the date we display in the TextView
	private void updateDisplay(TextView tv) {
		// Month is 0 based so add 1
		tv.setText(new StringBuilder().append(mDay).append("-").append(mMonth + 1).append("-").append(mYear).append(" "));
	}

	// the callback received when the user "sets" the date in the dialog
	private DatePickerDialog.OnDateSetListener mDateSetListenerFrom = new DatePickerDialog.OnDateSetListener() {

		public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
			mYear = year;
			mMonth = monthOfYear;
			mDay = dayOfMonth;
			updateDisplay(mDateDisplayFrom);
		}
	};

	// the callback received when the user "sets" the date in the dialog
	private DatePickerDialog.OnDateSetListener mDateSetListenerTo = new DatePickerDialog.OnDateSetListener() {

		public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
			mYear = year;
			mMonth = monthOfYear;
			mDay = dayOfMonth;
			updateDisplay(mDateDisplayTo);
		}
	};

	// final TextView lblMensaje = (TextView) findViewById(R.id.LblMensaje);

	// final Button btnBoton1 = (Button) findViewById(R.id.BtnBoton1);

	// final Spinner fromSpinner = (Spinner) findViewById(R.id.spinner);
	// ArrayAdapter adapter = ArrayAdapter.createFromResource(this,
	// R.array.citiesFrom, android.R.layout.simple_spinner_item);
	// adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
	// fromSpinner.setAdapter(adapter);
	//
	// Spinner toSpinner = (Spinner) findViewById(R.id.spinnerTo);
	// ArrayAdapter adapter1 = ArrayAdapter.createFromResource(this,
	// R.array.citiesTo, android.R.layout.simple_spinner_item);
	// adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
	// toSpinner.setAdapter(adapter1);
	//
	// // capture our View elements
	// mDateDisplayFrom = (TextView) findViewById(R.id.dateDisplayFrom);
	// mPickDateFrom = (Button) findViewById(R.id.pickDateFrom);
	//
	// // add a click listener to the button
	// mPickDateFrom.setOnClickListener(new View.OnClickListener() {
	// public void onClick(View v) {
	// showDialog(DATE_DIALOG_ID);
	// }
	// });
	//
	// // capture our View elements
	// mDateDisplayTo = (TextView) findViewById(R.id.dateDisplayTo);
	// mPickDateTo = (Button) findViewById(R.id.pickDateTo);
	//
	// // add a click listener to the button
	// mPickDateTo.setOnClickListener(new View.OnClickListener() {
	// public void onClick(View v) {
	// showDialog(DATE_DIALOG_ID);
	// }
	// });
	//
	// // get the current date
	// final Calendar c = Calendar.getInstance();
	// mYear = c.get(Calendar.YEAR);
	// mMonth = c.get(Calendar.MONTH);
	// mDay = c.get(Calendar.DAY_OF_MONTH);
	//
	// // display the current date
	// updateDisplay(mDateDisplayFrom);
	// updateDisplay(mDateDisplayTo);
	//
	// btnBoton1.setOnClickListener(new View.OnClickListener() {
	// //@Override
	// public void onClick(View arg0) {
	// // lblMensaje.setText("Bot�n 1 pulsado!");
	//
	// // TODO REFACTORAIZAR ESTO CON UN COMMAND
	// RequestOperation request = new RequestOperation();
	// request.init();
	//
	// Book book = new Book();
	// book = request.getBook();
	//
	// Item itemFrom = new Item();
	// itemFrom = book.getFromItem();
	//
	// List<String> itemsFrom = itemFrom.getWeekAvailable();
	// String resultFrom = new String();
	// for (int j = 0; j < itemFrom.getWeekAvailable().size(); j++) {
	// resultFrom += "\n----" + itemsFrom.get(j);
	// }
	//
	// Item itemTo = new Item();
	// itemTo = book.getToItem();
	//
	// String resultTo = new String();
	// List<String> itemsTo = itemTo.getWeekAvailable();
	// for (int k = 0; k < itemTo.getWeekAvailable().size(); k++) {
	// resultTo += "\n----" + itemsTo.get(k);
	// }
	// lblMensaje.setText("\n IDA---- \n" + resultFrom + "\n\n" +
	// "\n VUELTA----" + resultTo);
	//
	// }
	// });
	//
	// }
	//
	// @Override
	// protected Dialog onCreateDialog(int id) {
	// switch (id) {
	// case DATE_DIALOG_ID:
	// return new DatePickerDialog(this, mDateSetListener, mYear, mMonth,
	// mDay);
	// }
	// return null;
	// }
	//
	// private void updateDisplay(TextView textView) {
	// textView.setText(new StringBuilder()
	// // Month is 0 based so add 1
	// .append(mMonth +
	// 1).append("-").append(mDay).append("-").append(mYear).append(" "));
	// }
	//
	// private DatePickerDialog.OnDateSetListener mDateSetListener = new
	// DatePickerDialog.OnDateSetListener() {
	//
	// public void onDateSet(DatePicker view, int year, int monthOfYear, int
	// dayOfMonth) {
	// mYear = year;
	// mMonth = monthOfYear;
	// mDay = dayOfMonth;
	// }

}
